feat: implement programmatic lasso selection#236
Merged
flekschas merged 4 commits intoflekschas:mainfrom Jan 13, 2026
Merged
Conversation
- Add polygon selection API to select() method - Accepts array of [x,y] coordinate pairs in data space - Reuses existing findPointsInLasso() with KD-tree - Supports merge and remove modes - Add programmatic-lasso.js example with interactive demo - Update README with API documentation and examples - Add to Examples menu in Tweakpane
5 tasks
flekschas
requested changes
Jan 6, 2026
Owner
There was a problem hiding this comment.
🙌 Thanks for putting this together! 🎉 I really like this feature 👏 but I would say we should expose it as a new function: scatterplot.lasso(). I tried to flesh out the details as PR comments but there's more docs adjustments needed.
Most critically, we need a test :) You could add one that's essentially identical to https://github.com/flekschas/regl-scatterplot/blob/main/tests/events.test.js#L312-L399 but uses the new lasso method instead of emitting events. We should be testing:
- data space lasso polygon
- GL space lasso polygon
- an open polygon
- edge cases like when less than 3 vertices are passed to the lasso() function or the user uses vertices in data space without xScale and yScale
- Replace overloaded select(polygon) with lassoSelect(vertices) API - Add isVertices() validation checking all vertices - Add verticesToPolygon() helper to auto-close polygons - Rename polygonDataToGl to verticesFromDataToGl for clarity - Addtests - Update programmatic-lasso example to use new API - Update changelog.md
flekschas
approved these changes
Jan 13, 2026
Owner
flekschas
left a comment
There was a problem hiding this comment.
This looks great! 🎉 Thanks for the adjustments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
scatterplot.lassoSelect(vertices, options)method to enable automated point selection without manual interaction. Vertices can be specified in data space (using xScale/yScale) or GL space (isGl: true). This provides a programmatic alternative to the interactive lasso tool.What was changed in this pull request?
New API:
lassoSelect(vertices, { merge, remove, isGl })- dedicated method for programmatic lassovertices- array of[x, y]coordinates (minimum 3 vertices)isGl: false(default) - vertices in data space, requires xScale/yScaleisGl: true- vertices in GL space, works without scalesHelper functions:
isVertices()- validates all vertices are valid[x, y]pairsverticesToPolygon()- auto-closes polygons if first/last vertices differverticesFromDataToGl()- converts data space → GL space coordinatesExample
Why is this PR necessary?
Checklist
CHANGELOG.mdupdatedREADME.mdadded or updated